﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="原料到货记录录入.aspx.cs" Inherits="syc.Store.原料到货记录录入" %>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server" onsubmit="return checkinput();">
<asp:Label ID="Label_ID" runat="server" Text="0" Visible="false"></asp:Label>
<asp:Label ID="Label_List" runat="server" Text="" Visible="false"></asp:Label>

<asp:HiddenField ID="Date1" runat="server" />
<asp:HiddenField ID="BangLiang" runat="server" />
<asp:HiddenField ID="KuQu" runat="server" />
<asp:HiddenField ID="CheHao" runat="server" />
<asp:HiddenField ID="BeiZhu" runat="server" />
<asp:HiddenField ID="LuHao" runat="server" />
<asp:HiddenField ID="PiCi" runat="server" />
<asp:HiddenField ID="ZhongLiang" runat="server" />
<asp:HiddenField ID="ZhiShu" runat="server" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
SelectCommand="select ID, 名称 FROM 原料供货单位"></asp:SqlDataSource>


<span id="wintop" class="wintop" style="display:none;">原料到货登记</span>
<asp:Panel ID="Panel1" runat="server" CssClass="panel">
<div style="float:left">


    <asp:Button ID="Button_Save" runat="server" Text="保 存" UseSubmitBehavior="false"
            CssClass="button" onclick="Button_Save_Click"/>
            
    <input type="button" class="button" value="合并同炉号" onclick="hebing();" />

    <input type="button" value="导出Excel" class="button" onclick="Export();" />

    <asp:Button ID="Button_Close" runat="server" Text="关 闭" UseSubmitBehavior="false"  Visible="true"
            CssClass="button" OnClientClick="parent.swin2_close();return false;" />
    
</div>
<div style="float:right">

    <asp:Label ID="Label_PageNotice" runat="server" Text=""></asp:Label>       
<span style="display:inline-block;width:62px;"><asp:Button ID="Button_Prev" runat="server" Text="上一张" UseSubmitBehavior="false" Visible="false"
            CssClass="mbutton" onclick="Button_Prev_Click"/></span>
<span style="display:inline-block;width:62px;"><asp:Button ID="Button_Next" runat="server" Text="下一张" UseSubmitBehavior="false" Visible="false"
            CssClass="mbutton" onclick="Button_Next_Click"/></span>
</div>
</asp:Panel>

<style>
select{font-size:12pt;}
td.bb{border:0.5pt solid black;text-align:center;height:20pt;}
span.ed{display:inline-block;width:3cm;height:22px;line-height:22px;overflow:hidden;background-color:#d2e8ae;}
</style>
<script>putBillHead();</script>
<asp:Panel ID="Panel3" runat="server" CssClass="panel3">
<table id=mt border=0  cellpadding=0 style='border-collapse: collapse;font-size:12pt; font-family:宋体;'>
<tr>
<td colspan=4 style='height:40pt;font-size:20pt;font-weight:bold;text-align:center;'>管 材 到 (发) 货 登 记 表</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td style='font-size:11pt;'>编码：SYC/ZJ-WL-07</td>
</tr>
<tr>
<td class=bb colspan=2 style='text-align:left;height:24pt;'>　供货单位：<asp:DropDownList 
    ID="GongHuo" runat="server" DataSourceID="SqlDataSource1"  Width="150" Font-Size="14px"
    DataTextField="名称" DataValueField="ID"></asp:DropDownList></td>
<td class=bb colspan=2 style='text-align:left;'>　到货日期：<span id=box_Date class=ed onfocus="makecalendar(this.innerHTML, this);"></span></td>
</tr>
<tr>
<td class=bb colspan=2 style='text-align:left;height:24pt;'>　品　　名：<asp:DropDownList ID="LeiBie" runat="server" Width="150" Font-Size="14px">
    <asp:ListItem Text="油管光管(J55)" Value="1"></asp:ListItem>
    <asp:ListItem Text="套管光管(J55)" Value="2"></asp:ListItem>
    <asp:ListItem Text="油管接箍光管(J55)" Value="3"></asp:ListItem>
    <asp:ListItem Text="套管接箍光管(J55)" Value="4"></asp:ListItem>
    <asp:ListItem Text="成品油管接箍(J55)" Value="5"></asp:ListItem>
    <asp:ListItem Text="成品套管接箍(J55)" Value="6"></asp:ListItem>
    
    <asp:ListItem Text="油管光管(N80Q)" Value="101"></asp:ListItem>
    <asp:ListItem Text="套管光管(N80Q)" Value="102"></asp:ListItem>
    <asp:ListItem Text="油管接箍光管(N80Q)" Value="103"></asp:ListItem>
    <asp:ListItem Text="套管接箍光管(N80Q)" Value="104"></asp:ListItem>
    <asp:ListItem Text="成品油管接箍(N80Q)" Value="105"></asp:ListItem>
    <asp:ListItem Text="成品套管接箍(N80Q)" Value="106"></asp:ListItem>
    </asp:DropDownList></td>
<td class=bb colspan=2 style='text-align:left;'>　规　　格：<span id=Label_GuiGe></span></td>
</tr>
<tr>
<td class=bb colspan=2 style='text-align:left;height:24pt;'>　钢　　级：<span id=Label_GangJi></span></td>
<td class=bb colspan=2 style='text-align:left;'>　磅量(吨)：<span id=box_BangLiang class=ed style='width:4cm;'></span></td>
</tr>

<tr>
<td class=bb colspan=2 style='text-align:left;height:24pt;'>　使用分厂：<asp:DropDownList ID="FenChang" runat="server" Width="120"  Font-Size="14px">
    <asp:ListItem Text="" Value="0"></asp:ListItem>
    <asp:ListItem Text="一分厂" Value="1"></asp:ListItem>
    <asp:ListItem Text="二分厂" Value="2"></asp:ListItem>
    <asp:ListItem Text="三分厂" Value="3"></asp:ListItem>
    <asp:ListItem Text="四分厂" Value="4"></asp:ListItem>
    <asp:ListItem Text="五分厂" Value="5"></asp:ListItem>
    </asp:DropDownList></td>
<td class=bb colspan=2 style='text-align:left;'>　存储库区：<span  id=box_KuQu class=ed style='width:4cm;'></span></td>
</tr>

<tr>
<td class=bb colspan=4 style='text-align:left;height:30pt;'>　车　号：<span id=box_CheHao class=ed style='width:14cm;'></span></td>
</tr>
<tr>
<td class=bb colspan=4 style='text-align:left;height:30pt;border-bottom:2.5pt double black;'>　备　注：<span id=box_BeiZhu class=ed style='width:14cm;'></span></td>
</tr>
<tr>
<td class=bb style='width:4.5cm;'>炉号</td>
<td class=bb style='width:4.5cm;'>批次</td>
<td class=bb style='width:4cm;'>支数</td>
<td class=bb style='width:4cm;'>重量(吨)</td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>
<tr>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
<td class=bb><span class=ed></span></td>
</tr>

<tr>
<td class=bb>合计：</td>
<td class=bb></td>
<td class=bb></td>
<td class=bb></td>
</tr>
</table>
</asp:Panel>
<script>putBillFoot();</script>

</form>
<form id="form2" method="post" action="/PageExport.ashx">
<input type="hidden" name="filename" value="管材到(发)货登记表.xls" />
<input type="hidden" name="content" value="" />
</form>
<script>
    var notice = "<%=this.Notice %>";
    if (notice != "") {
        parent.showmsgbox(notice);
    }
    var readonly = <%=this.IsReadonly.ToString().ToLower() %>;
</script>
<script language="javascript">
    var guige = "73*5.51|139.7*7.72|88.9*12.5|153.67*13.5|88.9*12.5|5-1/2 LC|73*5.51|139.7*7.72|88.9*12.5|153.67*13.5|88.9*12.5|153.67*13.5".split("|");
    var mt = document.getElementById("mt");
    var gonghuo = document.getElementById("GongHuo");
    var leibie = document.getElementById("LeiBie");
    var fenchang = document.getElementById("FenChang");


    function hideblank() {
        for (var i = 28; i > 9; i--) {
            if (mt.rows[i].innerText.replace(" ", "") != "") {
                break;
            } else if (mt.rows[i - 1].innerText.replace(" ", "") != "") {
                mt.rows[i].style.display = "";
                break;
            }
            else {
                mt.rows[i].style.display = "none";
            }
        }
    }
    //计算合计
    function sum(c) {
        var res = 0;
        var t;
        for (var i = 0; i < 20; i++) {
            t = Number(mt.rows[i + 9].cells[c].innerText);
            if (t > 0) {
                res += t;
            }
        }
        return res;
    }
    
    //初始化
    function init() {
        document.getElementById("box_Date").innerHTML = document.getElementById("Date1").value;
        document.getElementById("box_BangLiang").innerHTML = fixFloat(document.getElementById("BangLiang").value, 3);
        document.getElementById("box_KuQu").innerHTML = document.getElementById("KuQu").value;
        document.getElementById("box_CheHao").innerHTML = document.getElementById("CheHao").value;
        document.getElementById("box_BeiZhu").innerHTML = document.getElementById("BeiZhu").value;
        var LuHao = document.getElementById("LuHao").value.split("|");
        var PiCi = document.getElementById("PiCi").value.split("|");
        var ZhongLiang = document.getElementById("ZhongLiang").value.split("|");
        var ZhiShu = document.getElementById("ZhiShu").value.split("|");
        for (var i = 0; i < LuHao.length && i< 20 ; i++) {
            mt.rows[i + 9].cells[0].innerHTML = "<span class=ed>" + LuHao[i] + "</span>";
            mt.rows[i + 9].cells[1].innerHTML = "<span class=ed>" + PiCi[i] + "</span>";
            mt.rows[i + 9].cells[2].innerHTML = "<span class=ed>" + ZhiShu[i] + "</span>";
            mt.rows[i + 9].cells[3].innerHTML = "<span class=ed>" + fixFloat(ZhongLiang[i], 3) + "</span>";
        }
        mt.rows[29].cells[2].innerHTML = fixFloat(sum(2), 3);
        mt.rows[29].cells[3].innerHTML = fixFloat(sum(3), 3);
        var spans = document.getElementsByTagName("span");
        if (readonly) {
            gonghuo.parentNode.innerHTML = "　供货单位："+gonghuo.options[gonghuo.selectedIndex].text;
            leibie.parentNode.innerHTML = "　品　　名：" + leibie.options[leibie.selectedIndex].text.split("(")[0];
            fenchang.parentNode.innerHTML = "　使用分厂：" + fenchang.options[fenchang.selectedIndex].text;
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].className == "ed") {
                    spans[i].className = "";
                }
            }
        }
        else {
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].className == "ed") {
                    spans[i].contentEditable = true;
                    spans[i].tabIndex = 0;
                    if (spans[i].parentNode.cellIndex ==0 && spans[i].parentNode.parentNode.rowIndex >8) {
                        spans[i].ondblclick = function() { copyrow(this); };
                    }
                }
            }
        }
        hideblank();
    }
    function copyrow(o) {
        var lh = getFirstTag(o.parentNode, "SPAN").innerText;
        if (lh == "") {
            return;
        }
        var r = o.parentNode.parentNode.rowIndex;
        for(var i=r+1;i<29;i++)
        {
            if (mt.rows[i].innerText == "") {
                getFirstTag(mt.rows[i].cells[0], "SPAN").innerHTML = getFirstTag(mt.rows[r].cells[0], "SPAN").innerHTML
                getFirstTag(mt.rows[i].cells[1], "SPAN").innerHTML = getFirstTag(mt.rows[r].cells[1], "SPAN").innerHTML
                break;
            }
        }
    }
    function getFirstTag(o,tagName) {
        var tag = o.firstChild;
        while (tag && tag.tagName.toUpperCase() != tagName.toUpperCase()) {
            tag = tag.nextSibling;
        }
        return tag;
    }
    document.getElementById("box_BangLiang").ondblclick = function() {
        if (leibie.value == "5") {
            this.innerHTML = fixFloat((new Number(mt.rows[29].cells[3].innerText)) * 2.3 / 1000, 3);
        }
        else if (leibie.value == "6") {
            this.innerHTML = fixFloat((new Number(mt.rows[29].cells[3].innerText)) * 6 / 1000, 3);
        }
    };
    //当原料类别变化
    function onleibiechange() {
        document.getElementById("Label_GuiGe").innerHTML = guige[leibie.selectedIndex];
        document.getElementById("Label_GangJi").innerHTML = leibie.options[leibie.selectedIndex].text.split("(")[1].replace(")", "");
        var bl=document.getElementById("box_BangLiang");
    }
    leibie.onchange = onleibiechange;
    onleibiechange();
    init();
    
    //按键处理
    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;

        if (tag.tagName == "INPUT" && tag.className == "textbox" || tag.tagName == "SELECT" || tag.tagName == "SPAN") {
            if (e.keyCode == 13) {
                e.keyCode = 9;
            }
        }
        else if (e.keyCode == 8) {
            return false;
        }
    }



    //导出Excel
    function Export() {
        var rows;
        var code = document.getElementById("Panel3").innerHTML;
        if (!readonly) {
            code = code.replace(/<select.*<\/select>/i, gonghuo.options[gonghuo.selectedIndex].text);
            code = code.replace(/<select.*<\/select>/i, leibie.options[leibie.selectedIndex].text.split("(")[0]);
            code = code.replace(/<select.*<\/select>/i, fenchang.options[fenchang.selectedIndex].text);
        }
        code = code.replace(/<span[^>]*>/img, "");
        code = code.replace(/<\/span>/img, "");
        rows=code.match(/<TR>/img).length;
        code = code.replace(/<\/TBODY>/i, "<tr><td colspan=4>物料中心留存</td></tr></TBODY>") + code.replace(/<\/TBODY>/i, "<tr><td colspan=4>分厂留存</td></tr></TBODY>");

        code = code.replace(/\n/img, "");
        code = code.replace(/<\/TBODY>.*<TBODY>/img, "");
        
        //删除空行
        code = code.replace(/<TR[^>]*>([\r\n]+<TD[^>]*><\/TD>)+<\/TR>/img, "");

        form2.content.value =
"<html xmlns:o='urn:schemas-microsoft-com:office:office'\nxmlns:x='urn:schemas-microsoft-com:office:excel'\nxmlns='http://www.w3.org/TR/REC-html40'>\n<head>\n<meta http-equiv=Content-Type content='text/html; charset=utf-8'>\n<style>\n<!--table\n@page\n{mso-header-data:;\nmso-footer-data:;\nmargin:.79in .31in .59in .31in;\nmso-header-margin:.51in;\nmso-footer-margin:.51in;\nmso-horizontal-page-align:center;\n}\ntd{font-size:12pt;text-align:center;mso-number-format:'\@';}\ntd.bb{border:0.5pt solid black;height:22pt;}\n-->\n</style>\n<!--[if gte mso 9]><xml>\n<x:ExcelWorkbook>\n<x:ExcelWorksheets>\n<x:ExcelWorksheet>\n<x:Name>管材到货(发)登记表</x:Name>\n<x:WorksheetOptions>\n<x:DefaultRowHeight>285</x:DefaultRowHeight>\n<x:Print>\n<x:ValidPrinterInfo/>\n<x:Scale>100</x:Scale>\n<x:PaperSizeIndex>9</x:PaperSizeIndex>\n<x:HorizontalResolution>200</x:HorizontalResolution>\n<x:VerticalResolution>200</x:VerticalResolution>\n</x:Print>\n<x:ShowPageBreakZoom/>\n<x:PageBreakZoom>100</x:PageBreakZoom>\n<x:Selected/>\n<x:Panes>\n<x:Pane>\n<x:Number>3</x:Number>\n<x:ActiveRow>0</x:ActiveRow>\n<x:ActiveCol>0</x:ActiveCol>\n</x:Pane>\n</x:Panes>\n</x:WorksheetOptions>\n"
        + "<x:PageBreaks><x:RowBreaks>" + "<x:RowBreak><x:Row>" + rows + "</x:Row></x:RowBreak>" + "</x:RowBreaks></x:PageBreaks>" + "</x:ExcelWorksheet>\n</x:ExcelWorkbook>\n</xml><![endif]-->\n</head>\n<body>"
        + code + "</body></html>";
        form2.submit();
    }



    //编辑后检测
    document.onfocusout = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.id == "box_Date") {

        }
        else if (tag.id == "box_BangLiang") {
            if (tag.innerText.indexOf("+", 0) > -1) {
                try {
                    tag.innerHTML = fixFloat(eval(tag.innerText), 3);
                }
                catch (e) {
                }
            }
            if ((tag.innerText != "" && !Number(tag.innerText)) || tag.innerText < 0) {
                parent.showmsgbox("“磅量”只能录入正数。");
                tag.style.color = "red";
            }
            else {
                tag.style.color = "";
            }
        }
        else if (tag.id == "box_KuQu") {
            if (leibie.value == "5" || leibie.value == "6") {
                if (tag.innerText != "0" && tag.innerText != "") {
                    parent.showmsgbox("成品接箍的“存储库区”应填0或者不填写");
                    tag.style.color = "red";
                }
                else {
                    tag.style.color = "";
                }
            }
            else {
                if (tag.innerText.match(/[^0-9]/) || tag.innerText > 100) {
                    parent.showmsgbox("“存储库区”只能录入 1 ～ 100 的数");
                    tag.style.color = "red";
                }
                else {
                    tag.style.color = "";
                }
            }
        }
        else if (tag.tagName == "SPAN" && tag.parentNode.tagName == "TD") {
            if (tag.parentNode.cellIndex == 3) {
                if ((tag.innerText != "" && !Number(tag.innerText)) || tag.innerText < 0) {
                    parent.showmsgbox("“重量”只能录入正数。");
                    tag.style.color = "red";
                }
                else {
                    tag.style.color = "";
                }
                mt.rows[29].cells[3].innerHTML = fixFloat(sum(3), 3);
            }
            else if (tag.parentNode.cellIndex == 2) {
                if (tag.innerText.match(/[^0-9]/) || tag.innerText < 0) {
                    parent.showmsgbox("“支数”只能录入正整数。");
                    tag.style.color = "red";
                }
                else {
                    tag.style.color = "";
                    if (leibie.selectedIndex == 5 && tag.innerText!="") {
                        getFirstTag(mt.rows[tag.parentNode.parentNode.rowIndex].cells[3], "SPAN").innerHTML
                            = fixFloat(Number(tag.innerText) * 6 / 1000, 3);
                    }
                }
                mt.rows[29].cells[2].innerHTML = sum(2);
            }
            hideblank();
        }
    };


    //提交前检测
    function checkinput() {
        var o = document.getElementById("box_BangLiang");
        if (o.innerText == "") {
            parent.showmsgbox("“磅量”必须填写。");
            return false;
        }
        else if ((!Number(o.innerText)) || o.innerText <= 0) {
            parent.showmsgbox("“磅量”只能录入正数。");
            o.style.color = "red";
            return false;
        }
        var o = document.getElementById("box_KuQu");
        if (leibie.value == "5" || leibie.value == "6") {
            if (o.innerText != "0" && o.innerText != "") {
                parent.showmsgbox("成品接箍的“存储库区”应录入0或为空");
                o.style.color = "red";
                return false;
            }
        }
        else {
            if (o.innerText == "") {
                parent.showmsgbox("“存储库区”需要录入。");
                return false;
            }
            else if (o.innerText.match(/[^0-9]/) || o.innerText > 100) {
                parent.showmsgbox("“存储库区”应录入 1 ～ 100 的数");
                o.style.color = "red";
                return false;
            }
        }


        if (leibie.value == "1" && (fenchang.value != "2" && fenchang.value != "5")
            || leibie.value == "2" && (fenchang.value != "1" && fenchang.value != "2")
            || (leibie.value == "3" || leibie.value == "4") && (fenchang.value != "3" && fenchang.value != "4")
            || (leibie.value == "5" || leibie.value == "6") && fenchang.value != "0") {
            parent.showmsgbox("原料类别与使用分厂不匹配");
            return false;
        }

        var LuHao = document.getElementById("LuHao");
        var PiCi = document.getElementById("PiCi");
        var ZhongLiang = document.getElementById("ZhongLiang");
        var ZhiShu = document.getElementById("ZhiShu");

        var count = 0;

        LuHao.value = "";
        PiCi.value = "";
        ZhongLiang.value = "";
        ZhiShu.value = "";

        for (var i = 0; i < 20; i++) {
            if (mt.rows[i + 9].innerText != "") {
                if (mt.rows[i + 9].cells[0].innerText == ""
                    || mt.rows[i + 9].cells[2].innerText == ""
                    || mt.rows[i + 9].cells[3].innerText == "") {
                    parent.showmsgbox("第 " + (i + 1) + " 行记录数据不完整");
                    return false;
                }
                else {
                    count++;
                }
            }
            LuHao.value += mt.rows[i + 9].cells[0].innerText + "|";
            PiCi.value += mt.rows[i + 9].cells[1].innerText + "|";
            ZhiShu.value += mt.rows[i + 9].cells[2].innerText + "|";
            ZhongLiang.value += mt.rows[i + 9].cells[3].innerText + "|";
        }
        if (count == 0 && !readonly) {
            parent.showmsgbox("您还没有录入到货记录明细");
            return false;
        }
        document.getElementById("Date1").value = document.getElementById("box_Date").innerText;
        document.getElementById("BangLiang").value = document.getElementById("box_BangLiang").innerText;
        document.getElementById("KuQu").value = document.getElementById("box_KuQu").innerText;
        document.getElementById("CheHao").value = document.getElementById("box_CheHao").innerText;
        document.getElementById("BeiZhu").value = document.getElementById("box_BeiZhu").innerText;

        return true;
    }
    function hebing() {
        var i,j;
        for (i = 28; i > 9; i--) {

            for (j = 9; j < i; j++) {

                if (getFirstTag(mt.rows[i].cells[0], "SPAN").innerText != ""
                    && getFirstTag(mt.rows[i].cells[0], "SPAN").innerText == getFirstTag(mt.rows[j].cells[0], "SPAN").innerText
                    && getFirstTag(mt.rows[i].cells[1], "SPAN").innerText == getFirstTag(mt.rows[j].cells[1], "SPAN").innerText) {
                    
                    getFirstTag(mt.rows[j].cells[2], "SPAN").innerHTML = Number(getFirstTag(mt.rows[i].cells[2], "SPAN").innerText) + Number(getFirstTag(mt.rows[j].cells[2], "SPAN").innerText);
                    getFirstTag(mt.rows[j].cells[3], "SPAN").innerHTML = Number(getFirstTag(mt.rows[i].cells[3], "SPAN").innerText) + Number(getFirstTag(mt.rows[j].cells[3], "SPAN").innerText);
                    getFirstTag(mt.rows[i].cells[0], "SPAN").innerHTML="";
                    getFirstTag(mt.rows[i].cells[1], "SPAN").innerHTML="";
                    getFirstTag(mt.rows[i].cells[2], "SPAN").innerHTML="";
                    getFirstTag(mt.rows[i].cells[3], "SPAN").innerHTML="";
                }
            }
        }
    }
</script>
</body>
</html>
